﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QldtSdh.BLL;
using QldtSdh.DAL.Models;
using QldtSdh.GUI.Common;

namespace QldtSdh.GUI.NCS
{
    public partial class FormQuanLyThongBao : BaseDialog
    {
        public FormQuanLyThongBao()
        {
            InitializeComponent();
            gridThongBao.AutoGenerateColumns = false;
            LoadThongBao();
        }

        void LoadThongBao()
        {
            var ls = BizThongBaoNCS.GetList();
            bsThongBao.DataSource = ls;
            gridThongBao.DataSource = bsThongBao;
        }

        private void bsThongBao_CurrentChanged(object sender, EventArgs e)
        {
            var thongBao = bsThongBao.Current as ThongBaoNCS;
            lvNguoiNhan.Items.Clear();
            if (thongBao != null)
            {
                txtTieuDe.Text = thongBao.TieuDe;
                txtNoiDung.Text = thongBao.NoiDung;
                if (!string.IsNullOrEmpty(thongBao.DSNguoiNhan))
                {
                    var lsID = thongBao.DSNguoiNhan.Split(new char[] { ';' });
                    if (lsID != null && lsID.Count() > 0)
                    {
                        int i = 1;
                        foreach (var id in lsID)
                        {
                            var ncs = BizNghienCuuSinh.GetByID(id);
                            ListViewItem lv = new ListViewItem(i.ToString());
                            lv.SubItems.Add(ncs.HoTen);
                            lv.SubItems.Add(ncs.NgaySinh);
                            lv.SubItems.Add(ncs.Email);
                            lv.SubItems.Add(ncs._KhoaHoc);
                            lv.SubItems.Add(ncs._NganhHoc);
                            lvNguoiNhan.Items.Add(lv);
                            i++;
                        }
                    }
                }
            }
        }
    }
}
